using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using OpenMVCRM.Entities;

namespace OpenMVCRM.DataAccess
{
    class PhoneNumberDA : BaseDA
    {
        public static OperationStatus SavePhoneNumber(PhoneNumber phone)
        {

            var opStatus = new OperationStatus();

            using (var conn = new SqlConnection(connString))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "uspSavePhoneNumber";
                    cmd.Parameters.AddWithValue("@Id", phone.ID);
                    cmd.Parameters.AddWithValue("@phoneNumber", phone.Number);
                    cmd.Parameters.AddWithValue("@type", phone.Type);
                    cmd.Parameters.AddWithValue("@isPrimary", phone.IsPrimary);
                    cmd.Parameters.AddWithValue("@ownerId", phone.OwnerID);

                    DbParameter returnValue;
                    returnValue = cmd.CreateParameter();
                    returnValue.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(returnValue);

                    conn.Open();
                    cmd.ExecuteNonQuery();
                    int result = Convert.ToInt32(returnValue.Value);
                    conn.Close();
                    opStatus.OperationID = result;
                    opStatus.Status = true;
                }
            }

            return opStatus;
        }
    }
}
